package com.quick.controller.system;
import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.quick.common.annotation.Log;
import com.quick.common.core.controller.BaseController;
import com.quick.common.core.domain.ApiResponse;
import com.quick.common.enums.BusinessTypeEnum;
import com.quick.system.domain.SysNotice;
import com.quick.system.service.SysNoticeService;
import com.quick.common.utils.poi.ExcelUtil;
/**
 * 通知公告Controller
 *
 * @Author: 吃素不吃肉
 * @Date: Tue Jul 25 14:14:44 CST 2023
 */
@Api(value = "通知公告管理", tags = {"通知公告操作接口"})
@RestController
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController {
    @Autowired
    private SysNoticeService sysNoticeService;

   /**
    * 查询通知公告列表
    */
    @PreAuthorize("@ps.hasPermission('system:notice:list')" )
    @GetMapping("/list")
    @ApiOperation(value = "分页查询通知公告列表")
    public ApiResponse list(SysNotice sysNotice) {
        try {
            startPage();
            List<SysNotice> list = sysNoticeService.selectSysNoticeList(sysNotice);
            return paging(list);
        } finally {
            clearPage();
        }

    }

    /**
     * 导出通知公告列表
     */
    @PreAuthorize("@ps.hasPermission('system:notice:export')" )
    @Log(title = "通知公告", businessType = BusinessTypeEnum.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出通知公告列表")
    public void export(HttpServletResponse response, SysNotice sysNotice) {
        List<SysNotice> list = sysNoticeService.selectSysNoticeList(sysNotice);
        ExcelUtil<SysNotice> util = new ExcelUtil<>(SysNotice.class);
        util.exportExcel(response, list, "通知公告数据");
    }

    /**
     * 获取通知公告详细信息
     */
    @PreAuthorize("@ps.hasPermission('system:notice:query')")
    @GetMapping(value = "/{noticeId}")
    @ApiOperation(value = "获取通知公告详细信息")
    public ApiResponse getInfo(@PathVariable("noticeId") Long noticeId) {
        return success(sysNoticeService.selectSysNoticeByNoticeId(noticeId));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ps.hasPermission('system:notice:add')")
    @Log(title = "通知公告", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation(value = "新增通知公告")
    public ApiResponse add(@RequestBody SysNotice sysNotice) {
        return success(sysNoticeService.insertSysNotice(sysNotice));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ps.hasPermission('system:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改通知公告")
    public ApiResponse edit(@RequestBody SysNotice sysNotice) {
        return success(sysNoticeService.updateSysNotice(sysNotice));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ps.hasPermission('system:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessTypeEnum.DELETE)
    @DeleteMapping("/{noticeIds}")
    @ApiOperation(value = "删除通知公告")
    public ApiResponse remove(@PathVariable Long[] noticeIds) {
        return success(sysNoticeService.deleteSysNoticeByNoticeIds(noticeIds));
    }
}
